package com.yxplearn.mybatisplus.game;

import com.yxplearn.mybatisplus.util.DateUtil;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TickService implements ApplicationContextAware {

    private static final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    private static long lastTickTime = 0;// 毫秒


    private static Runnable tick = () -> {
        long now = System.currentTimeMillis();
        if(DateUtil.isSameDay(lastTickTime)){
            dayRest(lastTickTime);
        }
//        ...

        lastTickTime = System.currentTimeMillis();
    };

    private static void dayRest(long lastTickTime) {

    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        scheduledExecutorService.scheduleAtFixedRate(tick, 1, 1, TimeUnit.MINUTES);
    }
}
